package com.guigu.qingcheng.orderservice.controller;


import com.guigu.qingcheng.orderservice.service.TbPreferentialService;
import com.guigu.qingcheng.pojo.order.TbPreferential;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/orderservice/tb-preferential")
public class TbPreferentialController {
    @Autowired
    private TbPreferentialService tbPreferentialService;

    @GetMapping("/preferential/findById")
    public R findById (Integer id) {
        TbPreferential tbPreferential = tbPreferentialService.getById(id);
        if (tbPreferential  == null)
            return R.error();
        return R.ok().data("tbPreferential",tbPreferential);
    }

    //查询分页查询
    @PostMapping("/preferential/findPage")
    public R findPage (@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestBody(required = false) Map<String,Object> searchMap ) {
        return tbPreferentialService.findPage(page, size, searchMap);
    }

    //新增
    @PostMapping("/preferential/add")
    public R add (@RequestBody TbPreferential tbPreferential) {
        boolean save = tbPreferentialService.save(tbPreferential);
        if (save)
            return R.ok();
        return R.error();
    }

    //修改
    @PostMapping("/preferential/update")
    public R update (@RequestBody TbPreferential tbPreferential) {
        boolean save = tbPreferentialService.updateById(tbPreferential);
        if (save)
            return R.ok();
        return R.error();
    }

    //删除
    @GetMapping("/preferential/delete")
    public R delete (String id) {
        boolean save = tbPreferentialService.removeById(id);
        if (save)
            return R.ok();
        return R.error();
    }
}

